/*
 * @Author: yxfan
 * @Date: 2024-12-16 19:15:35
 * @LastEditTime: 2025-01-11 17:53:04
 * @FilePath: /umi-demo/src/pages/test/redux/store.js
 * @Description:
 */
import { create } from 'zustand';
import { shallow } from 'zustand/shallow';
import { redux } from 'zustand/middleware';
import { useShallow } from 'zustand/react/shallow';

// export const useBearStore = create((set) => ({
//     bears: 0,
//     increasePopulation: () => set((state) => ({ bears: state.bears + 1 })),
//     removeAllBears: () => set({ bears: 0 }),
// }));

function reducer(state, action) {
    const { type, payload } = action;
    switch (type) {
        case 'setName':
            return {
                ...state,
                name: payload,
            };
        case 'setParent':
            return {
                ...state,
                parent: payload,
            };
        default:
            return state;
    }
}

const initState = {
    bears: 0,
};
export const useBearStore = create(redux(reducer, initState));
export const useBearStoreShallow = (selector) =>
    useBearStore(useShallow(selector));
useBearStoreShallow.getState = useBearStore.getState;
